/*jshint esversion: 9 */
//参数加密工具
import {Encrypt} from "./Crypto.js";

//用于数据交互时的字符加密  （比如参数）
export function encryptParam(str){
    str = str.toString();
    let confuseObj = new ConfuseStr();
    if (str.length>=1){
        return Encrypt(
            str,
            confuseObj.minusConfuse("N0O0M0;0:0;0?0P0H0P0B0P0;0O0J0K"),
            confuseObj.minusConfuse("R0E0G0;0:0;0?0P0H0P0B0P0;0O0J0K"),
        ); 
    }else{
        return null;
    }
    
}

//用于混淆字符串的类
class ConfuseStr{
    constructor(){}
    getStr(){  //获取固定的字符串用作截取
        let a = "@";
        let b = ".";
        let c = Array.from(new Array(123).keys()).slice(97).map(item=>{  //26个字母数组
            return String.fromCharCode(item);
        });
        let d = Array.from(new Array(58).keys()).slice(48).map(item=>{ //10个数字数组
            return String.fromCharCode(item);
        });
        return a+b+c.join('')+d.join('');
    }
    // addConfuse(str){  //加上混淆
    //     const string = this.getStr();
    //     return str.split('').map(item=>{
    //         return String.fromCharCode(string.indexOf(item)+58);
    //     }).join("0");
    // }
    minusConfuse(str){  //去掉混淆
        const stringList = this.getStr().split('');
        let data = '';
        for(let a of str.toString().split("0").map(item=>{return (item).toString().charCodeAt(0)-58;})){
            data =data + stringList[a];
        }
        return data;
    }
}